{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "numerous-stretch",
   "metadata": {},
   "source": [
    "https://leetcode.com/problems/design-add-and-search-words-data-structure\n",
    "\n",
    "\n",
    "Time Limit Exceeded\n",
    "\n",
    "\n",
    "```c++\n",
    "#include <vector>\n",
    "#include <algorithm>\n",
    "#include <string>\n",
    "#include <regex>\n",
    "\n",
    "using namespace std;\n",
    "\n",
    "class WordDictionary {\n",
    "public:\n",
    "    vector<int> length_list;\n",
    "    vector<string> list;\n",
    "    vector<char> table;\n",
    "    /** Initialize your data structure here. */\n",
    "    WordDictionary() {\n",
    "        //8:01\n",
    "        length_list.clear();\n",
    "        list.clear();\n",
    "        table.clear();\n",
    "        //8:13\n",
    "    }\n",
    "    \n",
    "    void addWord(string word) {\n",
    "        list.push_back(word);\n",
    "        if (find(length_list.begin(), length_list.end(), word.size()) == length_list.end()) {\n",
    "            length_list.push_back(word.size());\n",
    "        }\n",
    "        if (find(table.begin(), table.end(), word[0]) == table.end()) {\n",
    "            table.push_back(word[0]);\n",
    "        }\n",
    "    }\n",
    "    \n",
    "    bool search(string word) {\n",
    "        if (find(length_list.begin(), length_list.end(), word.size()) == length_list.end()) {\n",
    "            return false;\n",
    "        }\n",
    "        if (find(table.begin(), table.end(), word[0]) == table.end()) {\n",
    "            return false;\n",
    "        }\n",
    "        regex re_rules(word);\n",
    "        smatch strings_that_matchs;\n",
    "        for (auto w : list) {\n",
    "            regex_match(w, strings_that_matchs, re_rules);\n",
    "            if (strings_that_matchs.size() != 0) {\n",
    "                return true;\n",
    "            }\n",
    "        }\n",
    "        return false;\n",
    "    }\n",
    "};\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "scenic-flexibility",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "C++17",
   "language": "C++17",
   "name": "xcpp17"
  },
  "language_info": {
   "codemirror_mode": "text/x-c++src",
   "file_extension": ".cpp",
   "mimetype": "text/x-c++src",
   "name": "c++",
   "version": "17"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
